package ru.nnstu.medialib.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ru.nnstu.medialib.domain.Artist;

public class ArtistDAOImpl implements ArtistDAO {

	@Override
	public void saveArtist(Artist artist) {
		Session session = HibernateUtil.getSession();
		Transaction tr = session.beginTransaction();
		session.save(artist);
		tr.commit();
	}

	@Override
	public List<Artist> listArtist() {
		Session session = HibernateUtil.getSession();
		Criteria crit = session.createCriteria(Artist.class);
		return crit.list();
	}

	@Override
	public void removeArtist(Long id) {
		Session session = HibernateUtil.getSession();
		Object obj = session.load(Artist.class, id);
		session.delete(obj);
	}

}
